<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionDispatch::Assertions::RoutingAssertions</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionDispatch::Assertions::RoutingAssertions 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_dispatch/testing/assertions/routing_rb.html">actionpack/lib/action_dispatch/testing/assertions/routing.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Suite of assertions to test routes generated by Rails and the handling of
requests made to them.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="RoutingAssertions.html#method-i-assert_generates">assert_generates</a>,
              </li>
            
              
              <li>
                <a href="RoutingAssertions.html#method-i-assert_recognizes">assert_recognizes</a>,
              </li>
            
              
              <li>
                <a href="RoutingAssertions.html#method-i-assert_routing">assert_routing</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>M</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="RoutingAssertions.html#method-i-method_missing">method_missing</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>W</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="RoutingAssertions.html#method-i-with_routing">with_routing</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-assert_generates">
            
              <b>assert_generates</b>(expected_path, options, defaults={}, extras = {}, message=nil)
            
            <a href="RoutingAssertions.html#method-i-assert_generates" name="method-i-assert_generates" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Asserts that the provided options can be used to generate the provided
path. This is the inverse of <code>assert_recognizes</code>. The
<code>extras</code> parameter is used to tell the request the names and
values of additional request parameters that would be in a query string.
The <code>message</code> parameter allows you to specify a custom error
message for assertion failures.</p>

<p>The <code>defaults</code> parameter is unused.</p>

<pre># Asserts that the default action is generated for a route with no action
assert_generates &quot;/items&quot;, controller: &quot;items&quot;, action: &quot;index&quot;

# Tests that the list action is properly routed
assert_generates &quot;/items/list&quot;, controller: &quot;items&quot;, action: &quot;list&quot;

# Tests the generation of a route with a parameter
assert_generates &quot;/items/list/1&quot;, { controller: &quot;items&quot;, action: &quot;list&quot;, id: &quot;1&quot; }

# Asserts that the generated route gives us our custom route
assert_generates &quot;changesets/12&quot;, { controller: 'scm', action: 'show_diff', revision: &quot;12&quot; }</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assert_generates_source')" id="l_method-i-assert_generates_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a779ea9d57b00bd3b59f5546603271c2d302247c/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L72" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assert_generates_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assert_generates</span>(<span class="ruby-identifier">expected_path</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">defaults</span>={}, <span class="ruby-identifier">extras</span> = {}, <span class="ruby-identifier">message</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">expected_path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">%r{://}</span>
    <span class="ruby-identifier">fail_on</span>(<span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidURIError</span>) <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">expected_path</span>)
      <span class="ruby-identifier">expected_path</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">?</span> <span class="ruby-string">&quot;/&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">expected_path</span> = <span class="ruby-node">&quot;/#{expected_path}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">expected_path</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-string">'/'</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-comment"># Load routes.rb if it hasn't been loaded.</span>

  <span class="ruby-identifier">generated_path</span>, <span class="ruby-identifier">extra_keys</span> = <span class="ruby-ivar">@routes</span>.<span class="ruby-identifier">generate_extras</span>(<span class="ruby-identifier">options</span>, <span class="ruby-identifier">defaults</span>)
  <span class="ruby-identifier">found_extras</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">reject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span> <span class="ruby-identifier">extra_keys</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">k</span> }

  <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">message</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;found extras &lt;%s&gt;, not &lt;%s&gt;&quot;</span>, <span class="ruby-identifier">found_extras</span>, <span class="ruby-identifier">extras</span>)
  <span class="ruby-identifier">assert_equal</span>(<span class="ruby-identifier">extras</span>, <span class="ruby-identifier">found_extras</span>, <span class="ruby-identifier">msg</span>)

  <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">message</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;The generated path &lt;%s&gt; did not match &lt;%s&gt;&quot;</span>, <span class="ruby-identifier">generated_path</span>,
      <span class="ruby-identifier">expected_path</span>)
  <span class="ruby-identifier">assert_equal</span>(<span class="ruby-identifier">expected_path</span>, <span class="ruby-identifier">generated_path</span>, <span class="ruby-identifier">msg</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-assert_recognizes">
            
              <b>assert_recognizes</b>(expected_options, path, extras={}, msg=nil)
            
            <a href="RoutingAssertions.html#method-i-assert_recognizes" name="method-i-assert_recognizes" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Asserts that the routing of the given <code>path</code> was handled
correctly and that the parsed options (given in the
<code>expected_options</code> hash) match <code>path</code>. Basically, it
asserts that Rails recognizes the route given by
<code>expected_options</code>.</p>

<p>Pass a hash in the second argument (<code>path</code>) to specify the
request method. This is useful for routes requiring a specific HTTP method.
The hash should contain a :path with the incoming request path and a
:method containing the required HTTP verb.</p>

<pre># assert that POSTing to /items will call the create action on ItemsController
assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})</pre>

<p>You can also pass in <code>extras</code> with a hash containing URL
parameters that would normally be in the query string. This can be used to
assert that values in the query string string will end up in the params
hash correctly. To test query strings you must use the extras argument,
appending the query string on the path directly will not work. For example:</p>

<pre># assert that a path of '/items/list/1?view=print' returns the correct options
assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: &quot;print&quot; })</pre>

<p>The <code>message</code> parameter allows you to pass in an error message
that is displayed upon failure.</p>

<pre># Check the default route (i.e., the index action)
assert_recognizes({controller: 'items', action: 'index'}, 'items')

# Test a specific action
assert_recognizes({controller: 'items', action: 'list'}, 'items/list')

# Test an action with a parameter
assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')

# Test a custom route
assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assert_recognizes_source')" id="l_method-i-assert_recognizes_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a779ea9d57b00bd3b59f5546603271c2d302247c/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L40" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assert_recognizes_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assert_recognizes</span>(<span class="ruby-identifier">expected_options</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">extras</span>={}, <span class="ruby-identifier">msg</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span> = <span class="ruby-identifier">recognized_request_for</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">extras</span>)

  <span class="ruby-identifier">expected_options</span> = <span class="ruby-identifier">expected_options</span>.<span class="ruby-identifier">clone</span>

  <span class="ruby-identifier">expected_options</span>.<span class="ruby-identifier">stringify_keys!</span>

  <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">message</span>(<span class="ruby-identifier">msg</span>, <span class="ruby-string">&quot;&quot;</span>) {
    <span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;The recognized options &lt;%s&gt; did not match &lt;%s&gt;, difference:&quot;</span>,
            <span class="ruby-identifier">request</span>.<span class="ruby-identifier">path_parameters</span>, <span class="ruby-identifier">expected_options</span>)
  }

  <span class="ruby-identifier">assert_equal</span>(<span class="ruby-identifier">expected_options</span>, <span class="ruby-identifier">request</span>.<span class="ruby-identifier">path_parameters</span>, <span class="ruby-identifier">msg</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-assert_routing">
            
              <b>assert_routing</b>(path, options, defaults={}, extras={}, message=nil)
            
            <a href="RoutingAssertions.html#method-i-assert_routing" name="method-i-assert_routing" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Asserts that path and options match both ways; in other words, it verifies
that <code>path</code> generates <code>options</code> and then that
<code>options</code> generates <code>path</code>. This essentially combines
<code>assert_recognizes</code> and <code>assert_generates</code> into one
step.</p>

<p>The <code>extras</code> hash allows you to specify options that would
normally be provided as a query string to the action. The
<code>message</code> parameter allows you to specify a custom error message
to display upon failure.</p>

<pre># Assert a basic route: a controller with the default action (index)
assert_routing '/home', controller: 'home', action: 'index'

# Test a route generated with a specific controller, action, and parameter (id)
assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23

# Assert a basic route (controller + default action), with an error message if it fails
assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'

# Tests a route, providing a defaults hash
assert_routing 'controller/action/9', {id: &quot;9&quot;, item: &quot;square&quot;}, {controller: &quot;controller&quot;, action: &quot;action&quot;}, {}, {item: &quot;square&quot;}

# Tests a route with a HTTP method
assert_routing({ method: 'put', path: '/product/321' }, { controller: &quot;product&quot;, action: &quot;update&quot;, id: &quot;321&quot; })</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assert_routing_source')" id="l_method-i-assert_routing_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a779ea9d57b00bd3b59f5546603271c2d302247c/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L115" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assert_routing_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 115</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assert_routing</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">defaults</span>={}, <span class="ruby-identifier">extras</span>={}, <span class="ruby-identifier">message</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">assert_recognizes</span>(<span class="ruby-identifier">options</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">extras</span>, <span class="ruby-identifier">message</span>)

  <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">default_controller</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:controller</span>], <span class="ruby-identifier">defaults</span>[<span class="ruby-value">:controller</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">/</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">default_controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">default_controller</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">/</span>)
    <span class="ruby-identifier">options</span>[<span class="ruby-value">:controller</span>] = <span class="ruby-node">&quot;/#{controller}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">generate_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">delete_if</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">k</span>) }
  <span class="ruby-identifier">assert_generates</span>(<span class="ruby-identifier">path</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">path</span>[<span class="ruby-value">:path</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">path</span>, <span class="ruby-identifier">generate_options</span>, <span class="ruby-identifier">defaults</span>, <span class="ruby-identifier">extras</span>, <span class="ruby-identifier">message</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-method_missing">
            
              <b>method_missing</b>(selector, *args, &amp;block)
            
            <a href="RoutingAssertions.html#method-i-method_missing" name="method-i-method_missing" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>ROUTES TODO: These assertions should really work in an integration context</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-method_missing_source')" id="l_method-i-method_missing_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a779ea9d57b00bd3b59f5546603271c2d302247c/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L167" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-method_missing_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 167</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">method_missing</span>(<span class="ruby-identifier">selector</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@controller</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@routes</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@routes</span>.<span class="ruby-identifier">named_routes</span>.<span class="ruby-identifier">helpers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">selector</span>)
    <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">selector</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">super</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-with_routing">
            
              <b>with_routing</b>()
            
            <a href="RoutingAssertions.html#method-i-with_routing" name="method-i-with_routing" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>A helper to make it easier to test different route configurations. This
method temporarily replaces @routes with a new RouteSet instance.</p>

<p>The new instance is yielded to the passed block. Typically the block will
create some routes using <code>set.draw { match ... }</code>:</p>

<pre class="ruby"><span class="ruby-identifier">with_routing</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">set</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">set</span>.<span class="ruby-identifier">draw</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">resources</span> :<span class="ruby-identifier">users</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">assert_equal</span> <span class="ruby-string">&quot;/users&quot;</span>, <span class="ruby-identifier">users_path</span>
<span class="ruby-keyword">end</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-with_routing_source')" id="l_method-i-with_routing_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a779ea9d57b00bd3b59f5546603271c2d302247c/actionpack/lib/action_dispatch/testing/assertions/routing.rb#L141" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-with_routing_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 141</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">with_routing</span>
  <span class="ruby-identifier">old_routes</span>, <span class="ruby-ivar">@routes</span> = <span class="ruby-ivar">@routes</span>, <span class="ruby-constant">ActionDispatch</span><span class="ruby-operator">::</span><span class="ruby-constant">Routing</span><span class="ruby-operator">::</span><span class="ruby-constant">RouteSet</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@controller</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@controller</span>
    <span class="ruby-identifier">old_controller</span>, <span class="ruby-ivar">@controller</span> = <span class="ruby-ivar">@controller</span>, <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">clone</span>
    <span class="ruby-identifier">_routes</span> = <span class="ruby-ivar">@routes</span>

    <span class="ruby-comment"># Unfortunately, there is currently an abstraction leak between AC::Base</span>
    <span class="ruby-comment"># and AV::Base which requires having the URL helpers in both AC and AV.</span>
    <span class="ruby-comment"># To do this safely at runtime for tests, we need to bump up the helper serial</span>
    <span class="ruby-comment"># to that the old AV subclass isn't cached.</span>
    <span class="ruby-comment">#</span>
    <span class="ruby-comment"># TODO: Make this unnecessary</span>
    <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">singleton_class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:include</span>, <span class="ruby-identifier">_routes</span>.<span class="ruby-identifier">url_helpers</span>)
    <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">view_context_class</span> = <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">view_context_class</span>) <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">include</span> <span class="ruby-identifier">_routes</span>.<span class="ruby-identifier">url_helpers</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">yield</span> <span class="ruby-ivar">@routes</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-ivar">@routes</span> = <span class="ruby-identifier">old_routes</span>
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@controller</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@controller</span>
    <span class="ruby-ivar">@controller</span> = <span class="ruby-identifier">old_controller</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    